﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Win32;
using System.IO;

namespace DrawTools
{
    /// <summary>
    /// Interaction logic for StartDialog.xaml
    /// </summary>
    public partial class StartDialog : Window
    {
        private FileInfo pictureInfo;
        public StartDialog()
        {
            InitializeComponent();
        }

        private void rBtnDrawinEditing_Checked(object sender, RoutedEventArgs e)
        {
            btnSelectPicture.IsEnabled = true;
            txtBoxPicturePath.IsEnabled = true;
        }

        private void rBtnDrawin_Checked(object sender, RoutedEventArgs e)
        {
            btnSelectPicture.IsEnabled = false;
            txtBoxPicturePath.IsEnabled = false;
        }

        private void btnSelectPicture_Click(object sender, RoutedEventArgs e)
        {
                      OpenFileDialog selectModeFileDialog = new OpenFileDialog();

            selectModeFileDialog.Filter = "jpg files (*.jpg)|*.jpg|jpeg files (*.jpeg)|*.jpeg";
            selectModeFileDialog.RestoreDirectory = true;

            if (selectModeFileDialog.ShowDialog().Value)
            {
                try
                {
                    txtBoxPicturePath.Text = selectModeFileDialog.FileName;
                    pictureInfo = new FileInfo(selectModeFileDialog.FileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }

        }

        private void btnRunApp_Click(object sender, RoutedEventArgs e)
        {
            SettingsManager.OnStartup();
            Settings settings = new Settings();
            if (rBtnDrawing.IsChecked == true)
            {
                SettingsManager.PhotoEditingMode = false;
                MainWindow mainWindow = new MainWindow();
                mainWindow.Show();
                this.Close();
                SettingsManager.OnExit();

            }
            else if (rBtnEditing.IsChecked == true)
	        {
                SettingsManager.PhotoEditingMode = true;
                SettingsManager.EditedPicture = txtBoxPicturePath.Text;
	            SettingsManager.PictureInfo = pictureInfo;
                MainWindow mainWindow = new MainWindow();
                mainWindow.Show();
                this.Close();
                SettingsManager.OnExit();

	        }
            else
            {
                MessageBox.Show("Please select mode!","Warning");
            }


        }

    }
}
